<template>
  <view
    :style="{
      'padding-top': height + 'px',
      'box-sizing': 'border-box',
    }"
  >
    <view
      :style="{
        width: '100%',
        height: statusBarHeight + 'px',
        background: 'white',
        position: 'fixed',
        top: 0,
        zIndex: 100,
      }"
    >
    </view>
    <view
      class="head"
      :style="{
        top: statusBarHeight + 'px',
      }"
    >
      <view class="head_left">
        <u-icon
          name="arrow-left"
          color="#444444"
          size="24"
          :bold="true"
          @click="toBack"
        ></u-icon>
      </view>
      <view class="text">系统消息</view>
    </view>
    <view class="box" :style="{ marginTop: statusBarHeight + 'px' }" v-if="vlist && vlist.length>0">
      <scroll-view
        :style="{
          height: scrollHeihgt+'px',
        }"
        :scroll-y="true"
        @scroll="scroll"
        @scrolltolower="scrolltolower"
      >
        <view class="item" v-for="(item, index) in vlist" :key="index">
          <view class="item_time" v-if="!item.is_tong">
            <view class="time">
              {{ item.new_time }}
            </view>
          </view>
          <view class="content" v-if="item.title != '邀请加入星球'">
            {{ item.content }}
          </view>
          <view class="content1" v-else>
            <view class="content1_title">{{ item.content }}</view>
            <view class="content1_btn">
              <view
                class="content1_btn_red"
                v-if="item.status == 0"
                @click="operate(item, 2)"
                >拒绝</view
              >
              <view
                class="content1_btn_green"
                v-if="item.status == 0"
                @click="operate(item, 1)"
                >同意</view
              >
              <view class="content1_btn_grey" v-if="item.status != 0">{{
                item.status == 1 ? "已同意" : "已拒绝"
              }}</view>
            </view>
          </view>
        </view>
      </scroll-view>
    </view>

    <view class="empty_view" v-if="vlist && vlist.length == 0">
      <image
        class="item_left_clickable"
        src="../../static/images/my/kong.png"
        mode=""
      ></image>
      <view>当前暂无消息~</view>
    </view>
	<floatingBall></floatingBall>
  </view>
</template>

<script>
export default {
  data() {
    return {
      list: [],
      statusBarHeight: 0,
      scrollHeihgt:0,
      height: 0,
      vlist: [],
      page:1,
      last_page:0
    };
  },
  created() {
    const statusBarHeight = uni.getSystemInfoSync(); // 获取手机状态栏高度
    const windowHeihgt = statusBarHeight.windowHeight;
    this.statusBarHeight = statusBarHeight.statusBarHeight;
    this.$nextTick(() => {
      uni
        .createSelectorQuery()
        .select(".head")
        .boundingClientRect((data) => {
          this.height = data.height;
          this.scrollHeihgt = windowHeihgt - data.height - this.statusBarHeight
        })
        .exec();
    });

    
    this.getList();
  },
  methods: {
    toBack() {
      uni.navigateBack({
        delta: 1,
      });
    },
    getList() {
      this.$http
        .messageXitong_message({page:this.page})
        .then((res) => {
          this.vlist = this.vlist.concat(res.data.list.data);
          this.last_page = res.data.list.last_page
          // this.xiaoyaoList = data;
          // console.log(this.vlist, "系统详情");
        })
        .catch((error) => {
          uni.$u.toast(error);
        });
    },
    // 同意/拒绝
    operate(item, status) {
      this.$http
        .xingheJieshou_yaoqing({ id: item.id, status: status })
        .then((res) => {
          uni.$u.toast(res.message);
          // this.xiaoyaoList = data;
          // console.log(res, "同意或拒绝");
          this.getList();
        })
        .catch((error) => {
          uni.$u.toast(error);
        });
    },
    scroll() {},
    scrolltolower() {
      if (this.page == this.last_page || this.last_page == 0) {
      } else {
        this.page++
        this.getList()
      }
      // console.log("触发");
    },
  },
};
</script>

<style scoped lang="scss">
.head {
  width: 100%;
  padding: 18rpx 0 47rpx;
  position: fixed;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #fff;
  z-index: 10;
  .head_left {
    position: absolute;
    left: 30rpx;
  }
  .text {
    font-size: 36rpx;
    font-family: PingFang SC-Bold, PingFang SC;
    font-weight: 400;
    color: #444444;
  }
}
.box {
  padding: 0 30rpx;
  box-sizing: border-box;
  .item {
    width: 100%;
    .item_time {
      width: 100%;
      display: flex;
      justify-content: center;
      margin-top: 48rpx;
      .time {
        padding: 3rpx 20rpx;
        background: #f7f8fa;
        border-radius: 8rpx 8rpx 8rpx 8rpx;
        font-size: 26rpx;
        font-family: PingFang SC-Medium, PingFang SC;
        font-weight: 400;
        color: #888888;
      }
    }
    .content {
      margin-top: 32rpx;
      font-size: 32rpx;
      font-family: PingFang SC-Medium, PingFang SC;
      font-weight: 400;
      color: #444444;
      background: #f7f8fa;
      border-radius: 16rpx 16rpx 16rpx 16rpx;
      padding: 32rpx 40rpx;
      box-sizing: border-box;
    }
    .content1 {
      margin-top: 32rpx;
      font-size: 32rpx;
      font-family: PingFang SC-Medium, PingFang SC;
      font-weight: 400;
      color: #444444;
      background: #f7f8fa;
      border-radius: 16rpx 16rpx 16rpx 16rpx;
      padding: 32rpx 40rpx;
      box-sizing: border-box;
      .content1_btn {
        display: flex;
        align-items: center;
        justify-content: end;
        margin-top: 64rpx;
        color: white;
        .content1_btn_red {
          background: #ee6060;
          width: 166rpx;
          height: 72rpx;
          text-align: center;
          line-height: 72rpx;
          font-size: 30rpx;
          border-radius: 40rpx;
        }
        .content1_btn_green {
          background: #55b877;
          width: 166rpx;
          height: 72rpx;
          text-align: center;
          line-height: 72rpx;
          font-size: 30rpx;
          border-radius: 40rpx;
          margin-left: 16rpx;
        }
        .content1_btn_grey {
          background: #d8d8d8;
          width: 166rpx;
          height: 72rpx;
          text-align: center;
          line-height: 72rpx;
          font-size: 30rpx;
          border-radius: 40rpx;
        }
      }
    }
  }
}

.empty_view {
  margin-top: 300rpx;
  image {
    margin: 0 auto;
    width: 410rpx;
    height: 410rpx;
  }
  view {
    font-size: 30rpx;
    color: #d8d8d8;
    text-align: center;
  }
}
</style>